package org.dromara.bykt.controller;

import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import org.dromara.bykt.utils.AliOSSUpload;
import org.dromara.common.core.domain.R;
import org.dromara.system.domain.vo.SysOssUploadVo;
import org.dromara.system.domain.vo.SysOssVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ossUpload")
public class OssUploadController {

    @Autowired
    private AliOSSUpload aliOSSUpload;

    @PostMapping(value = "/uploadImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<String> uploadImage(@RequestPart("file") MultipartFile file) throws Exception {
        if (ObjectUtil.isNull(file)) {
            return R.fail("上传文件不能为空");
        }
        String s = aliOSSUpload.uploadImage(file);
        return R.ok("操作成功", s);
    }

    @PostMapping(value = "/uploadVideo", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<String> uploadVideo(@RequestPart("file") MultipartFile file) throws Exception {
        if (ObjectUtil.isNull(file)) {
            return R.fail("上传文件不能为空");
        }
        String s = aliOSSUpload.uploadVideo(file);
        return R.ok("操作成功", s);
    }
}
